package cn.jhc.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.dao.TitleDAO;

@WebServlet(name = "add order", urlPatterns = { "/addorder.do" })
public class AddOrderServlet extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
			String name = (String) req.getParameter("name");
			String college = (String) req.getParameter("college");
			String classname = (String) req.getParameter("classname");
			String chinesename = (String) req.getParameter("chinesename");
			String email = (String) req.getParameter("email");
			String phone = (String) req.getParameter("phone");
			String title = (String) req.getParameter("title");
			String amcount = (String) req.getParameter("amcount");
			int count = Integer.parseInt(amcount);
			System.out.println(count);
			String subtotal = (String) req.getParameter("subtotal");
			TitleDAO t = new TitleDAO();
			if (count != 0) {
				t.addOrder(name, college, classname, chinesename, email, phone,title, amcount, subtotal);
			}
		RequestDispatcher dispatcher = req.getRequestDispatcher("/index.jsp");
		dispatcher.forward(req, resp);
	}
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
}
